using System;
using System.ComponentModel;
using System.Transactions;

using SIS.ENT;
using SIS.DAL;


namespace SIS.BLL {

/// <summary>
/// The EducationPeriodStandardCourseTableManager class is responsible for managing BO.EducationPeriodStandardCourseTable objects in the system.
/// </summary>
[DataObjectAttribute()]
public class EducationPeriodStandardCourseTableManager
  {

#region "Public Methods"

/// <summary>
/// Gets a list with all EducationPeriodStandardCourseTable objects in the database.
/// </summary>
/// <returns>A list with all EducationPeriodStandardCourseTable from the database when the database contains any, or null otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Select, true)]
public static EducationPeriodStandardCourseTableList GetList(){
return EducationPeriodStandardCourseTableDB.GetList();
}

/// <summary>
/// Gets a single EducationPeriodStandardCourseTable from the database without its data.
/// </summary>
/// <param name="educationPeriodDetailKey">The EducationPeriodDetailKey of the EducationPeriodStandardCourseTable in the database.</param>
/// <returns>A EducationPeriodStandardCourseTable object when the EducationPeriodDetailKey exists in the database, or <see langword="null"/> otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Select, false)]
public static EducationPeriodStandardCourseTable GetItem(int educationPeriodDetailKey){
return GetItem(educationPeriodDetailKey, false);
}

/// <summary>
/// Gets a single EducationPeriodStandardCourseTable from the database.
/// </summary>
/// <param name="educationPeriodDetailKey">The EducationPeriodDetailKey of the EducationPeriodStandardCourseTable in the database.</param>
/// <param name="getEducationPeriodStandardCourseTableRecords">Determines whether to load all associated EducationPeriodStandardCourseTable records as well.</param>
/// <returns>
/// A EducationPeriodStandardCourseTable object when the EducationPeriodDetailKey exists in the database, or <see langword="null"/> otherwise.
/// </returns>
[DataObjectMethod(DataObjectMethodType.Select, false)]
public static EducationPeriodStandardCourseTable GetItem(int educationPeriodDetailKey, bool getEducationPeriodStandardCourseTableRecords){
EducationPeriodStandardCourseTable myEducationPeriodStandardCourseTable = EducationPeriodStandardCourseTableDB.GetItem(educationPeriodDetailKey);
if (myEducationPeriodStandardCourseTable != null && getEducationPeriodStandardCourseTableRecords){
myEducationPeriodStandardCourseTable.timeScheduleTables = TimeScheduleTableDB.GetListByEducationPeriodDetailKey(educationPeriodDetailKey);
}
return myEducationPeriodStandardCourseTable;
}

/// <summary>
/// Saves a EducationPeriodStandardCourseTable in the database.
/// </summary>
/// <param name="myEducationPeriodStandardCourseTable">The EducationPeriodStandardCourseTable instance to save.</param>
/// <returns>The new EducationPeriodDetailKey if the EducationPeriodStandardCourseTable is new in the database or the existing EducationPeriodDetailKey when an item was updated.</returns>
[DataObjectMethod(DataObjectMethodType.Update, true)]
public static int Save(EducationPeriodStandardCourseTable myEducationPeriodStandardCourseTable){
using (TransactionScope myTransactionScope = new TransactionScope()){
int educationPeriodStandardCourseTableEducationPeriodDetailKey = EducationPeriodStandardCourseTableDB.Save(myEducationPeriodStandardCourseTable);
foreach (TimeScheduleTable myTimeScheduleTable in myEducationPeriodStandardCourseTable.timeScheduleTables){
myTimeScheduleTable.EducationPeriodDetailKey = educationPeriodStandardCourseTableEducationPeriodDetailKey;
TimeScheduleTableDB.Save(myTimeScheduleTable);
}

//  Assign the EducationPeriodStandardCourseTable its new (or existing EducationPeriodDetailKey).
myEducationPeriodStandardCourseTable.EducationPeriodDetailKey = educationPeriodStandardCourseTableEducationPeriodDetailKey;

myTransactionScope.Complete();

return educationPeriodStandardCourseTableEducationPeriodDetailKey;
}
}

/// <summary>
/// Deletes a EducationPeriodStandardCourseTable from the database.
/// </summary>
/// <param name="myEducationPeriodStandardCourseTable">The EducationPeriodStandardCourseTable instance to delete.</param>
/// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Delete, true)]
public static bool Delete(EducationPeriodStandardCourseTable myEducationPeriodStandardCourseTable){
return EducationPeriodStandardCourseTableDB.Delete(myEducationPeriodStandardCourseTable.EducationPeriodDetailKey);
}

#endregion

}

}
